<template>
  <div class="examinationWrap">
    <div class="pageTableInner">
      <div class="infoSearchWrap">
        <div class="infoSearchOne">
          <div class="searchWrap">
            <el-row>
              <el-col :span="8"><span style="color:#50545D; ">企业考核名称：</span><span
                style="color:#3975FE; ">{{examineTask.examineName}}</span></el-col>
              <el-col :span="7"><span style="color:#50545D; ">考核时间范围：</span><span
                style="color:#3975FE; ">{{examineTask.examineBeginTime.split(" ")[0]}}—{{examineTask.examineEndTime.split(" ")[0]}}</span>
              </el-col>
              <el-col :span="7"><span style="color:#50545D; ">单位考核时间：</span><span
                style="color:#3975FE; ">{{examineTask.launchBeginTime.split(" ")[0]}}—{{examineTask.launchEndTime.split(" ")[0]}}</span>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8"><span style="color:#50545D; ">初步意见征询：</span><span
                style="color:#3975FE; ">{{examineTask.resultBeginTime.split(" ")[0]}}—{{examineTask.resultEndTime.split(" ")[0]}}</span>
              </el-col>
              <el-col :span="7"><span style="color:#50545D; ">考核审查认定：</span><span
                style="color:#3975FE; ">{{examineTask.checkBeginTime.split(" ")[0]}}—{{examineTask.checkEndTime.split(" ")[0]}}</span>
              </el-col>
              <el-col :span="7"><span style="color:#50545D; ">结果公示发布：</span><span
                style="color:#3975FE; ">{{examineTask.releaseBeginTime.split(" ")[0]}}—{{examineTask.releaseEndTime.split(" ")[0]}}</span>
              </el-col>
              <div style="float: right;margin-right: 10px;">
                <el-button type="primary" size="mini" @click="subMitEnter('ruleFormSet')">进入考核</el-button>
              </div>
            </el-row>
          </div>
        </div>
      </div>
      <div class="tableContainer" style="top: 105px;">
        <div class="tableInner" ref="tableInner">
          <el-table
            ref="multipleTable"
            :data="rows"
            stripe
            :height="tableHeight"
            :span-method="objectSpanMethod"
            tooltip-effect="dark"
            style="width: 100%"
          >
            <el-table-column
              label="指标类别"
              prop="classifyName"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              label="类别分值"
              prop="classifyScore"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="itemsName"
              label="指标项"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                {{scope.row.itemsName}}
              </template>
            </el-table-column>
            <el-table-column
              prop="standardScore"
              label="指标分值"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              label="指标描述"
              prop="itemsDesc"
              show-overflow-tooltip>
              <template slot-scope="scope">
                {{scope.row.itemsDesc}}
              </template>
            </el-table-column>
            <el-table-column
              label="评分标准"
              prop="scoreRule"
              show-overflow-tooltip
              >
              <template slot-scope="scope">
                <div style="float: left;">
                  {{scope.row.scoreRule}}
              </div>
              </template>
            </el-table-column>
            <el-table-column
              label="责任部门"
              prop="g"

            >
              <template slot-scope="scope">
                <el-row>
                  <el-col v-show="scope.row.hasRoadTransport" :span="12">
                    <span>市交通局</span>
                  </el-col>
                  <el-col v-show="scope.row.hasCityManage" :span="12">
                    <span>市城管局</span>
                  </el-col>
                  <el-col v-show="scope.row.hasTraffic" :span="12">
                    <span>市交警局</span>
                  </el-col>
                  <el-col v-show="scope.row.hasAreaGov" :span="12">
                    <span>各区政府</span>
                  </el-col>
                </el-row>
              </template>
            </el-table-column>
            <el-table-column
              label="附件管理"
              prop="hasAttachment"
              show-overflow-tooltip>
              <template slot-scope="scope">
                {{scope.row.hasAttachment ? "有附件" : "无附件"}}


              </template>
            </el-table-column>

          </el-table>

        </div>
      </div>
    </div>
    <router-view :taskId="taskId" :templateId="examineTask.templateId" :hasCheck1="hasCheck"
                 @getTempalteInfo="getTempalteInfo"></router-view>
  </div>
</template>

<script>
  import affixBtn from './affixBtn.vue';
  export default {
    props: [],
    data(){
      return {
        rows: [],
        nodataIsshow: false,
        examineTask: {
          examineBeginTime: "",
          examineEndTime: "",
          launchBeginTime: "",
          launchEndTime: "",
          resultBeginTime: "",
          resultEndTime: "",
          checkBeginTime: "",
          checkEndTime: "",
          releaseBeginTime: "",
          releaseEndTime: "",
        },
        tableHeight: 400,
        spanArr: [],
        totalScore: "",
        taskId: "",
        hasCheck: true,

      }
    },
    components: {affixBtn},
    created(){
      this.getTempalteInfo()

    },
    mounted(){
      setTimeout(() => {
        //表格滚动
        this.tableHeight = document.querySelector(".examinationWrap").clientHeight - 145
      }, 500)
    },

    methods: {
      //获取所有模板信息
      getTempalteInfo(){
        this.axios.post(process.env.API_HOST + `/examine/selectTask`, {})
          .then(response => {
            const result = response.data
            if (result.code == 200) {
              this.nodataIsshow = result.result.examineTask.id ? false : true
              this.examineTask = result.result.examineTask
              this.taskId = this.examineTask.id
              result.result.notAgencyTask.forEach(item => {
                if (this.$store.state.agencyId == item.agencyId) {
                  this.hasCheck = false
                  if (item.backAgree) {
                    this.$alert(item.backAgree, '考核退回信息', {
                      confirmButtonText: '确定',
                      type: 'warning'
                    }).then(() => {
                    }).catch(() => {
                    });
                  }
                }

              })

              this.getExamineInfo(this.examineTask.templateId)
            }else {

            }
          })
      },

      subMitEnter() {
        if (this.examineTask.id) {
          this.$router.push('/entering/examine')
        } else {
          this.$message({
            type: 'warning',
            message: "当前没有正在进行的考核任务"
          });
        }
      },

      //获取所有信息
      getExamineInfo(templateId){
        this.axios.post(process.env.API_HOST + `/examine/selectTemplate`, {templateId: templateId})
          .then(response => {
            let result = response.data
            if (result.code == 200) {
              this.rows = []
              result.result.templateInfoList.forEach(item => {
                item.itemList.forEach(item1 => {
                  this.rows.push({
                    ...item1,
                    classifyId: item.classifyId,
                    classifyName: item.classifyName,
                    classifyScore: ""
                  })
                })


              })
              if (this.rows.length > 0) {
                this.spanArr = this.getSpanArr(this.rows, "classifyName")
                this.rows.forEach((item, key) => {
                  this.totalScore += item.standardScore
                  this.getclassifyScore(key)
                })
              }

            }
          })

      },
      objectSpanMethod({row, column, rowIndex, columnIndex}) {
        if (columnIndex === 0 || columnIndex === 1) {
          const _row = this.spanArr[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
      },
      getclassifyScore(index){
        let sub = 0, isPass = true, classifyScore = 0
        this.spanArr.forEach(item => {
          sub += item
          if (isPass && sub > index) {
            isPass = false
            const sliceArr = this.rows.slice(sub - item, sub)
            sliceArr.forEach(item => {
              classifyScore += this.toDecimal(item.standardScore)
            })
            sliceArr.forEach(item => {
              item.classifyScore = classifyScore
            })
          }
        })

      },

    },
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import "../../../common/stylus/mixin.styl"
  .examinationWrap
    page()

</style>
